package com.gene.controller;

import com.gene.pojo.UserIncome;
import com.gene.service.IUserIncomeService;
import com.gene.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 用户收入账单详情
 */

@Controller
@RequestMapping("/gene-safe/userIncome")
public class UserIncomeController {
    @Autowired
    private IUserIncomeService userIncomeService;

/**
     * 查询mode（状态)=1收入的数据
     * 参数为userId
     * @param userIncome
     * @return
*/
    @RequestMapping(value="/query")
    @ResponseBody
    public ResultData query(UserIncome userIncome){
        ResultData result=new ResultData();
        List<UserIncome> list=userIncomeService.query(userIncome);
        if(list.size()>0){
            result.setData(list);
            result.setStatus("1");
            result.setMsg("查询成功！");
        }else{
            result.setStatus("0");
            result.setMsg("没有数据！");
        }
        return result;
    }


/**
     * 新增
     * @param userIncome
     * @return*/
    @RequestMapping(value="/add")
    @ResponseBody
    public ResultData add(UserIncome userIncome){
        ResultData result =new ResultData();
        boolean a=userIncomeService.add(userIncome);
        if(a){
            result.setStatus("1");
            result.setMsg("新增成功...");
        }else{
            result.setStatus("0");
            result.setMsg("新增失败！");
        }
        return result;
    }

    /**
     * 修改
     * @param userIncome
     * @return
    */
    @RequestMapping(value="/edit")
    @ResponseBody
    public ResultData edit(UserIncome userIncome){
        ResultData result =new ResultData();
        boolean a=userIncomeService.edit(userIncome);
        if(a){
            result.setStatus("1");
            result.setMsg("修改成功...");
        }else{
            result.setStatus("0");
            result.setMsg("修改失败！");
        }
        return result;
    }

/**
     * 删除
     * @param userIncome
     * @return*/
    @RequestMapping(value="/delete")
    @ResponseBody
    public ResultData delete(UserIncome userIncome) {
        ResultData result = new ResultData();
        boolean a=userIncomeService.delete(userIncome);
        if(a){
            result.setStatus("1");
            result.setMsg("删除成功...");
        }else{
            result.setStatus("0");
            result.setMsg("删除失败！");
        }
        return result;
    }
}
